<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>病人管理</title>
</head>

<body>
<div id="content" style="height: 500px;">
	<form id="form1" name="form1" action="" method="post">
		<fieldset>
    		<legend>简单查询</legend>
    		病人姓名:<input type="text" name="name" value="${patientSearch.name}" /> 
			病人身份证:<input type="text"  name="idCard" value="${patientSearch.idCard}" />
			年龄:<input type="text"  name="age" value="${patientSearch.age}" />
  		</fieldset>
  		<input type="checkbox" id="showAdvance" />显示高级查询
  		<fieldset id="advance" style="display: none">
    		<legend>高级查询</legend>
    		<table style="border-collapse:collapse;">
    			<tr>
    				<td>出生日期从:<input type="text"  onclick="WdatePicker()" name="fromDate" value="${patientSearch.fromDate}" /></td>
    				<td>&nbsp;&nbsp;到:<input type="text"  onclick="WdatePicker()" name="toDate" value="${patientSearch.toDate}" /></td>
    				<td>医保类型:<input type="text"  name="medicalInsType" value="${patientSearch.medicalInsType}" /></td>
    				<td>家庭住址:<input type="text"  name="address" value="${patientSearch.address}" /></td>
    			</tr>
    			<tr>
    				<td>联系电话:&nbsp;&nbsp;<input type="text"  name="contactNumber" value="${patientSearch.contactNumber}" /></td>
    				<td>QQ号:<input type="text"  name="qqNumber" value="${patientSearch.qqNumber}" /></td>
    				<td>药物过敏:<input type="text"  name="dragAllergy" value="${patientSearch.dragAllergy}" /></td>
    				<td>自诉病情:<input type="text"  name="self_condition" value="${patientSearch.self_condition}" /></td>
    			</tr>
    		</table>
  		</fieldset>
  		<br/>		
		<input id="search1"  type="button" value="查询" onclick="search()"/>
		<input id="new"  type="button" value="新增" onclick="toAdd()"/>
		<input id="delete"  type="button" value="删除" onclick="deleteAll()"/>
		<input type="hidden" id="currentPageNo" name="currentPageNo" value="${currentPageNo}">
		<input type="hidden" id="perPageNumber" name="perPageNumber" value="${perPageNumber}">
		<table id="mytable" cellspacing="0" summary="The technical specifications of the Apple PowerMac G5 series">  
		  <tr>
		  	<th><input type="checkbox" id="all" name="all"/></th> 
		    <th>序号</th> 
		    <th>姓名</th> 
		    <th>性别</th> 
		    <th>身份证号</th>
		    <th>出生日期</th>
		    <th>年龄</th>
		    <th>医保类型</th>
		    <th>家庭住址</th>
		    <th>联系电话</th>
		    <th>病历</th>
		    <th>操作</th> 
		  </tr> 
		  <c:forEach items="${patients}" var="patient" varStatus="i">
		  	<tr> 
		  		<td align="center"><input type="checkbox" id="selId" name="selId" value="${patient.id}" alt="${patient.name}"/></td> 
			   	<td align="center">${i.index+1}</td>
			    <td align="center"><a href="javascript:void(0)" onclick="view('${patient.id}')" >${patient.name}</a></td> 
			    <td align="center">${patient.gender eq 'F'?'女':'男'}</td>
			    <td align="center">${patient.idCard}</td> 
			    <td align="center"><fmt:formatDate value="${patient.birthday}" type="date" pattern="yyyy-MM-dd"/></td>
			    <td align="center">${patient.age}</td> 
			    <td align="center">${patient.medicalInsType}</td> 
			    <td align="center">${patient.address}</td>
			    <td align="center">${patient.contactNumber}</td> 
			    <td align="center"><a href="javascript:void(0)" onclick="viewMedicalRecord('${patient.id}')" >查看</a></td>
			    <td align="center">
			    	<a name="delete1"  href="javascript:void(0)" onclick="deleteOne('${patient.id}','${patient.name}')">删除</a>
			    	<a name="modify"  href="javascript:void(0)" onclick="toUpdatePage('${patient.id}')">修改</a>
			    </td>
		  	</tr> 
		  </c:forEach>
		</table> 
		<div id="Pagination" ></div>
	</form>
</div>
<div id="editDiv" style="width: 60%;background-color: white;overflow-y:auto;display: none">
	<div style="margin: 2%">
		<form id="addForm" action="/patient/add">
			<table style="border-collapse:collapse;width: 100%">
				<tr>
					<td>姓名</td>
					<td><input name="name" value="${patient.name}" /></td>
					<td>性别</td>
					<td>
						<input type="radio" name="gender" value="M" checked="checked"/>男
						<input type="radio" name="gender" value="F" ${patient.gender eq 'F'?'checked':''}/>女
					</td>
					<td>出生年月日</td>
					<td><input type="text" id="birthday" onclick="WdatePicker()" name="birthday" value="${patient.birthday}" /></td>
					<td>年龄</td>
					<td><label id="age">${patient.age}</label></td>
				</tr>
				<tr>
					<td>医保类型</td>
					<td colspan="2">
						<select id="medicalInsType" name="medicalInsType">
							<option ${patient.medicalInsType eq '省医保'?'selected':''}>省医保</option>
							<option ${patient.medicalInsType eq '市医保'?'selected':''}>市医保</option>
							<option ${patient.medicalInsType eq '农村医保'?'selected':''}>农村医保</option>
						</select>
					</td>
					<td>家庭住址</td>
					<td colspan="4">
						<input name="address" value=""${patient.address}/>
					</td>
				</tr>
				<tr>
					<td>联系电话</td>
					<td colspan="3">
						<input name="contactNumber" value=""${patient.contactNumber}/>
					</td>
					<td>QQ号码</td>
					<td colspan="3">
						<input name="qqNumber" value=""${patient.qqNumber}/>
					</td>
				</tr>
				<tr>
					<td>身份证号码</td>
					<td colspan="3">
						<input name="idCard" value=""${patient.idCard}/>
					</td>
					<td>药物过敏</td>
					<td colspan="3">
						<input name="dragAllergy" value=""${patient.dragAllergy}/>
					</td>
				</tr>
				<tr>
					<td>入院时病情自诉</td>
					<td colspan="7">
						<textarea name="self_condition" style="width: 99%;resize:none;"  rows="5" cols="">${patient.self_condition}</textarea>
					</td>
				</tr>
			</table>
			<input type="button" value="增加病历" onclick=""/>
			<input type="button" value="删除选中病历" onclick=""/>
			<table style="border-collapse:collapse;width: 100%">
				<tr id="">
					<td rowspan="3"><input type="checkbox" name="recordId"/>第1次入出院</td>
					<td>入院时间</td>
					<td><input type="text" id="" onclick="WdatePicker()" name="" value="" /></td>
					<td>接诊医生</td>
					<td>
						<select>
							<option>张三</option>
							<option>李四</option>
						</select>
					</td>
					<td>住院号</td>
					<td><input /></td>
				</tr>
				<tr>
					<td>诊断病情</td>
					<td colspan="5">
						<textarea style="width: 99%;resize:none;"  rows="5" cols=""></textarea>
					</td>
				</tr>
				<tr>
					<td>出院时间</td>
					<td><input type="text" id="" onclick="WdatePicker()" name="" value="" /></td>
					<td>治疗效果</td>
					<td colspan="3">
						<textarea style="width: 99%;resize:none;"  rows="5" cols=""></textarea>
					</td>
				</tr>
			</table>
		</form>
		<center>
			<input type="button" value="保存" onclick="save()"/>
			<input type="button" value="返 回" onclick="returnList('editDiv')"/>
		</center>	
	</div>
</div>
<div id="viewDiv" style="width: 60%;background-color: white;overflow-y:auto;display: none">
</div>
<script type="text/javascript">
var ctx = "${pageContext.request.contextPath}";
var page = "${currentPageNo}";
//初始化checkbox
jQuery("document").ready(function(){
	jQuery("#all").click(function(){
			var flag = document.getElementById("all").checked;
	   	 	jQuery("[name=selId]:checkbox").each(function() {
	        		jQuery(this).attr("checked", flag);
	   		});
   });
	$("#showAdvance").click(function(){
		var flag = document.getElementById("showAdvance").checked;
		if(flag){
			$("#advance").show();
		}else{
			$("#advance").hide();
		}
	});
	$("#Pagination").paginate({
		count 		: '${count}',	//页数
		start 		: '${currentPageNo}',
		display     : 10,
		border					: true,
		border_color			: '#BEF8B8',
		text_color  			: '#68BA64',
		background_color    	: '#CAE8EA',	
		border_hover_color		: '#68BA64',
		text_hover_color  		: 'black',
		background_hover_color	: '#CAE8EA', 
		rotate      : false,
		images		: false,
		mouse		: 'press',
		onChange     			: function(page){
									var formObj = document.getElementById("form1");
									$("#currentPageNo").val(page);
									formObj.action=ctx+'/patient/findAll';
									formObj.submit();
								  }
	});	   
});
function returnList(id){
	('#'+id).trigger('close');
}
function search(){
	var formObj = document.getElementById("form1");
	$("#currentPageNo").val(1);
	formObj.action=ctx+'/patient/findAll';
	formObj.submit();
}
function toAdd(){
	$('#editDiv').lightbox_me();
}
function view(id){
	$.ajax( {
		type : 'GET',
		url :"${pageContext.request.contextPath}/patient/ajaxView?id="+id,
		cache : false,
		async:false,
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			//alert(XMLHttpRequest.readyState);
		},
		success : function(data) {
			$("#viewDiv").html(data);
			$("#viewDiv").lightbox_me();
		}
	});
}
function toModify(){	
}
function save(){
	var formObj = document.getElementById("addForm");
	formObj.submit();
}

</script>
</body>
</html>
